package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.BaseContext;
import com.itheima.reggie.common.R;
import com.itheima.reggie.pojo.Orders;
import com.itheima.reggie.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

@RestController
@RequestMapping("/order")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        ordersService.submit(orders);
        return R.success("成功");
    }
    @GetMapping("/userPage")
    public R<Page<Orders>> page(@RequestParam Integer page, Integer pageSize){
        Page<Orders> pageInfo=new Page<>(page,pageSize);
        Long userId = BaseContext.getCurrentId();
        QueryWrapper<Orders> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        Page<Orders> ordersPage = ordersService.page(pageInfo, queryWrapper);
        return R.success(ordersPage);
    }
}
